package baidu_uid

type CachedUidGenerator struct {
	*DefaultUidGenerator
}

// Get the UIDs in the same specified second under the max sequence
//
// @param currentSecond
// @return UID list, size of {@link BitsAllocator#getMaxSequence()} + 1
func (cu *CachedUidGenerator) nextIdsForOneSecond(currentSecond int64) []int64 {
	// Initialize result list size of (max sequence + 1)
	listSize := cu.bitsAllocator.getMaxSequence() + 1
	uidList := make([]int64, listSize, listSize)

	// Allocate the first sequence of the second, the others can be calculated with the offset
	firstSeqUid := cu.bitsAllocator.allocate(currentSecond-cu.epochSeconds, cu.workerId, 0)
	for offset := int64(0); offset < listSize; offset++ {
		uidList = append(uidList, firstSeqUid+offset)
	}

	return uidList
}
